package com.cosina.game.llk;

import java.util.Random;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.drawable.Drawable;

public class ThemeManager {
	
	public static int imageCount  = 15; 
	
	public static final int NO_IMAGE = 0;
	
	
	private static ImageTheme currentTheme = ImageTheme.qq;
	
	public static ImageTheme getCurrentTheme(){
		return currentTheme;
	}
	
	public static void changeTheme(){ 
		ImageTheme[] themes = ImageTheme.values();
		int newIndex = -1;
		for( int i=0; i< themes.length; i++){
			if(currentTheme == themes[i]){
				newIndex = i+1;
				break;
			}
		}
		if(newIndex == -1 || newIndex == themes.length){
			newIndex = 0;
		}
		currentTheme = themes[newIndex];
	}
	
	public enum ImageTheme {
		qq(Color.BLACK),nba(Color.WHITE);
		
		private int backgroundColor;
		ImageTheme(int backgroundColor){
			this.backgroundColor = backgroundColor;
		}
		
		public int getBackgroundColor(){
			return backgroundColor;
		}
	}
	
	public static final int EACH_SIZE = 31;
	
	private static final Random random = new Random();
	
	public static int getRandomColor(int factor){
		return random.nextInt(factor);
	}
	
	public static Bitmap getImage(int id){
		if(currentTheme == ImageTheme.qq){
			return qqPics[id];
		}else{
			return nbaPics[id];
		}
	}
	
	
	public static final Bitmap[] qqPics = new Bitmap[imageCount + 1];
	public static final Bitmap[] nbaPics = new Bitmap[imageCount + 1];
	
	public static void init(Context context){
		{
			loadBallView(ImageTheme.qq, 1 , R.drawable.q1,context);
	    	loadBallView(ImageTheme.qq, 2, R.drawable.q2,context);
	    	loadBallView(ImageTheme.qq, 3, R.drawable.q3,context);
	    	loadBallView(ImageTheme.qq, 4, R.drawable.q4,context);
	    	loadBallView(ImageTheme.qq, 5, R.drawable.q5,context);
	    	loadBallView(ImageTheme.qq, 6, R.drawable.q6,context);
	    	loadBallView(ImageTheme.qq, 7, R.drawable.q7,context);
	    	loadBallView(ImageTheme.qq, 8, R.drawable.q8,context);
	    	loadBallView(ImageTheme.qq, 9, R.drawable.q9,context);
	    	loadBallView(ImageTheme.qq, 10, R.drawable.q10,context);
	    	loadBallView(ImageTheme.qq, 11, R.drawable.q11,context);
	    	loadBallView(ImageTheme.qq, 12, R.drawable.q12,context);
	    	loadBallView(ImageTheme.qq, 13, R.drawable.q13,context);
	    	loadBallView(ImageTheme.qq, 14, R.drawable.q14,context);
	    	loadBallView(ImageTheme.qq, 15, R.drawable.q15,context);
		}
		{
			loadBallView(ImageTheme.nba, 1, R.drawable.n1,context);
	    	loadBallView(ImageTheme.nba, 2, R.drawable.n2,context);
	    	loadBallView(ImageTheme.nba, 3, R.drawable.n3,context);
	    	loadBallView(ImageTheme.nba, 4, R.drawable.n4,context);
	    	loadBallView(ImageTheme.nba, 5, R.drawable.n5,context);
	    	loadBallView(ImageTheme.nba, 6, R.drawable.n6,context);
	    	loadBallView(ImageTheme.nba, 7, R.drawable.n7,context);
	    	loadBallView(ImageTheme.nba, 8, R.drawable.n8,context);
	    	loadBallView(ImageTheme.nba, 9, R.drawable.n9,context);
	    	loadBallView(ImageTheme.nba, 10, R.drawable.n10,context);
	    	loadBallView(ImageTheme.nba, 11, R.drawable.n11,context);
	    	loadBallView(ImageTheme.nba, 12, R.drawable.n12,context);
	    	loadBallView(ImageTheme.nba, 13, R.drawable.n13,context);
	    	loadBallView(ImageTheme.nba, 14, R.drawable.n14,context);
	    	loadBallView(ImageTheme.nba, 15, R.drawable.n15,context);
		}
		
	}
	
    private static void loadBallView(ImageTheme theme,int color, int resId,Context context) {
		Drawable ballPic = context.getResources().getDrawable(resId);
		Bitmap bitmap = Bitmap.createBitmap(EACH_SIZE, EACH_SIZE, Bitmap.Config.ARGB_8888);
        
        Canvas canvas = new Canvas(bitmap);
        ballPic.setBounds(0, 0, EACH_SIZE, EACH_SIZE);
        ballPic.draw(canvas);
        if(theme == ImageTheme.qq){
        	qqPics[color] = bitmap;
        }else{
        	nbaPics[color] = bitmap;
        }
    }
}
